package com.huayi.test.springbootcomm.trans.service;

import com.alibaba.fastjson.JSONObject;
import com.huayi.test.springbootcomm.constant.ErrCodeInfo;
import com.huayi.test.springbootcomm.exception.BizException;
import com.huayi.test.springbootcomm.service.IserviceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseService implements IService{

    private static final Logger LOG = LoggerFactory.getLogger(BaseService.class);
    public abstract void action (IserviceContext context) throws Exception;

    @Override
    public void excute(IserviceContext context) {
        LOG.info("BaseService.excute() begin to start>>>>>>>>>>>>>>>>>>>>>");
        Map<String, Object> respMap = context.getRespMap();
        try {
            action(context);
        }catch (BizException e){
            LOG.error("调用交易失败,错误码[{}],错误信息[{}]",e.getErrCode(),e.getErrMessage());
            respMap.put("respCode",e.getErrCode());
            respMap.put("respMsg",e.getErrMessage());
            e.printStackTrace();
        }catch (Exception e){
            respMap.put("respCode", ErrCodeInfo.FALIURE.getErrCode());
            respMap.put("respMsg",ErrCodeInfo.FALIURE.getErrMsg());
            e.printStackTrace();
        }
        LOG.info("BaseService.excute() end<<<<<<<<<<<<<<<<");
    }

    /***
     * 返回响应码
     * @param body
     * @return
     */
}
